<template>
  <view class="page-body">
	  <u-navbar :is-back="false" title="销售报表填写"
	    title-size="30"
	    :background="{background:'#2B88FE' }"
	    title-color="#fff">
	    <div class="head_icon">
	      <u-icon @click="$api.handleBackTo"
	        name="arrow-left" color="#fff"
	        size="36">
	      </u-icon>
	      <u-icon @click="$api.handleHomeTo"
	        name="home" color="#fff" size="36">
	      </u-icon>
	    </div>
	  </u-navbar>
    <block v-if="type==0">
      <view class="iptbox">
        <view class="iname">
          今日完成工作
        </view>
        <textarea v-model="fContent" placeholder="请输入内容"></textarea>
      </view>
      <view class="iptbox">
        <view class="iname">
          未完成工作
        </view>
        <textarea v-model="fNotDo" placeholder="请输入内容"></textarea>
      </view>
    </block>
    <block v-if="type=='1'">
      <view class="iptbox">
        <view class="iname">
          本周完成工作
        </view>
        <textarea v-model="fContent" placeholder="请输入内容"></textarea>
      </view>
      <view class="iptbox">
        <view class="iname">
          本周工作总结
        </view>
        <textarea v-model="fSumUp" placeholder="请输入内容"></textarea>
      </view>
      <view class="iptbox">
        <view class="iname">
          下周工作计划
        </view>
        <textarea v-model="fNextPlan" placeholder="请输入内容"></textarea>
      </view>
    </block>
    <block v-if="type=='2'">
      <view class="iptbox">
        <view class="iname">
          本月工作内容
        </view>
        <textarea v-model="fContent" placeholder="请输入内容"></textarea>
      </view>
      <view class="iptbox">
        <view class="iname">
          本月工作总结
        </view>
        <textarea v-model="fSumUp " placeholder="请输入内容"></textarea>
      </view>
      <view class="iptbox">
        <view class="iname">
          下月工作计划
        </view>
        <textarea v-model="fNextPlan" placeholder="请输入内容"></textarea>
      </view>
    </block>
    <view class="iptbox">
      <view class="iname">
        需协调与帮助
      </view>
      <textarea v-model="fNeedHelp" placeholder="请输入内容"></textarea>
    </view>
    <view class="iptbox" style="padding-right: 0;">
      <view class="iname">
        上传图片
      </view>
      <u-upload ref="uUpload" max-count="8" name="file" :header="header" :action="action"
        :auto-upload="true">
      </u-upload>
      <view class="" style="height: 30rpx;">

      </view>
    </view>

    <view class="iptbox">
      <view class="iname">
        发送到人
      </view>
      <view class="sends">
        <view class="sli" v-for="(s,sidx) in send" :key="sidx">
          <image :src="s.avatar">
          </image>
          <view class="sname ellipsis">
            {{s.nickname}}
          </view>
        </view>
      </view>
    </view>
    <view class="whiteBg sendBtn">
      <!-- <u-button class="tj"></button> -->
      <u-button type="primary" @click="gotoSend" :ripple="true" ripple-bg-color="#f2f2f2">提 交
      </u-button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      header: {
        token: uni.getStorageSync('token')
      },
      action: this.urlimg + 'api/Upfile/PostImgFile',
      type: '',
      fContent: '', //今日完成
      fNotDo: '', //今日完成
      fSumUp: '', //总结
      fNextPlan: '', //下次计划
      fNeedHelp: '', //协调工作
      send: []
    }
  },
  onLoad(e) {
    // 公用页面，日报，周报，月报提交
    this.type = parseInt(e.type)
    //
    switch (this.type) {
      case 0:
        uni.setNavigationBarTitle({
          title: '写日报'
        })
        break
      case 1:
        uni.setNavigationBarTitle({
          title: '写周报'
        })
        break
      case 2:
        uni.setNavigationBarTitle({
          title: '写月报'
        })
        break
    }
  },
  methods: {
    gotoSend() {
      let that = this,
        txt = '',
        t = this.type,
        f = []
      if (t == 1) {
        if (!this.fContent) txt = '请输入周报内容'
        else if (!this.fSumUp) txt = '请输入本周工作总价'
        else if (!this.fNextPlan) txt = '请输入下周工作计划'
      } else if (t == 2) {
        if (!this.fContent) txt = '请输入本月工作内容'
        else if (!this.fSumUp) txt = '请输入本月工作总价'
        else if (!this.fNextPlan) txt = '请输入下月工作计划'
      } else {
        if (!this.fContent) txt = '请输入今日工作内容'
      }
      if (txt) {
        uni.showToast({
          title: txt,
          icon: 'none'
        })
        return
      }
      let info = {
        fType: this.type + 1,
        fContent: this.fContent, //今日完成
        fNotDo: this.fNotDo, //今日完成
        fPics: this.$api.getreqImg(this.$refs.uUpload.lists),
        fNeedHelp: this.fNeedHelp, //协调工作
        fNextPlan: this.fNextPlan,
        fSumUp: this.fSumUp
      }
      this.$axios('api/WorkSummary/AddDetail', 'post', { value: info }).then(res => {
		  if (!res.Success) {
		    uni.showToast({
		      title: '提交失败：'+res.Message,
		      icon: 'none',
		      duration: 2000
		    })
		    return false
		  }
		  
        this.$api.handleBack('添加成功')
      })
    }
  }
}
</script>

<style lang="scss">
page {
  background: #f8f9fc;
}

.sendBtn {
  padding: 14rpx 48rpx;
  box-sizing: border-box;

  .tj {
    .u-btn {
      height: 84rpx;
      background: #2b88fe;
      border-radius: 8rpx;
      line-height: 84rpx;
      font-size: 32rpx;
      color: #ffffff;
    }
  }
}

.page-body {
  padding-top: 32rpx;
}

.iptbox {
  width: 686rpx;
  margin: 0 32rpx 16rpx 32rpx;
  background-color: #ffffff;
  box-shadow: 0px 2rpx 8rpx 0px rgba(237, 241, 253, 1);
  border-radius: 16rpx;
  padding: 0 32rpx;
  box-sizing: border-box;

  .iname {
    padding: 32rpx 0;
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
    line-height: 44rpx;
  }

  textarea {
    height: 132rpx;
  }
}

.sends {
  overflow: auto;

  .sli {
    float: left;
    width: 20%;
    text-align: center;

    image {
      width: 80rpx;
      height: 80rpx;
      border-radius: 50%;
      margin-bottom: 8rpx;
      background-color: #f2f2f2;
    }

    .sname {
      height: 80rpx;
      font-size: 28rpx;
      font-weight: 400;
      color: #333333;
      line-height: 40rpx;
    }
  }
}
</style>
